/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

/**
 *
 * @author Andy
 */
@Entity(name = "CompletedGoodsLocation")
public class CompletedGoodsLocationEntity extends LocationEntity implements Serializable {

    int capacityCase;
    int usageCase;
    int remainingCase;
    int toAddCase;
    int showBarCase;
    //String type;
    @OneToMany(mappedBy = "location")
    private Collection<LocationQuantityEntity> locationToQuantity = new ArrayList<LocationQuantityEntity>();
    private boolean anyExpiring;

    public CompletedGoodsLocationEntity() {
        super();
        super.setType("CG");
    }

        public boolean isAnyExpiring() {
        System.out.println("In any expiring");
        Date currentDate = new Date();
        SimpleDateFormat sdfDate = new SimpleDateFormat("dd/MM/yyyy");
        sdfDate.format(currentDate);
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.DATE, 30);  // number of days to add

        List<LocationQuantityEntity> lqeList = new ArrayList<LocationQuantityEntity>(this.getLocationToQuantity());
         System.out.println("In any expiring lqe size"+ lqeList.size());
        for (LocationQuantityEntity lqe : lqeList) {
            if (lqe.getInventory().getBatch().getExpiryDate().before(c.getTime()) && lqe.isArchived()==false) {
                anyExpiring=true;
                return anyExpiring;
            }
        }
        anyExpiring=false;
        return anyExpiring;
    }
    
//
//    public String getType() {
//        return type;
//    }
//
//    public void setType(String type) {
//        this.type = type;
//    }
    public Collection<LocationQuantityEntity> getLocationToQuantity() {
        return locationToQuantity;
    }

    public void setLocationToQuantity(Collection<LocationQuantityEntity> locationToQuantity) {
        this.locationToQuantity = locationToQuantity;
    }

    public void update() {
    }

    public int getShowBarCase() {
        showBarCase = usageCase + toAddCase;
        showBarCase = showBarCase / 10;
        return showBarCase;
    }

    public void setShowBarCase(int showBarCase) {
        this.showBarCase = showBarCase;
    }

    public int getToAddCase() {
        return toAddCase;
    }

    public void setToAddCase(int toAddCase) {
        this.toAddCase = toAddCase;
    }

    public int getRemainingCase() {
        remainingCase = capacityCase - usageCase;
        return remainingCase;
    }

    public void setRemainingCase(int remainingCase) {
        this.remainingCase = remainingCase;
    }

    public int getCapacityCase() {
        return capacityCase;
    }

    public void setCapacityCase(int capacityCase) {
        this.capacityCase = capacityCase;
    }

    public int getUsageCase() {
        return usageCase;
    }

    public void setUsageCase(int usageCase) {
        this.usageCase = usageCase;
    }
}
